package com;

import com.dao.UserDao;
import com.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.*;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@ComponentScan //扫描项目中的bean类
@Configuration //说明本项目是IOC配置类0
@EnableAspectJAutoProxy
public class AppConfig {
    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
   //     User user = (User) ctx.getBean(User.class);
    //    System.out.println(user);
        UserService userService = ctx.getBean(UserService.class);
        boolean flag = userService.login("张三","123");
        if(flag){
            System.out.println("登陆成功");
        }else {
            System.out.println("登陆失败");
        }
        UserDao userDao = ctx.getBean(UserDao.class);
        userDao.delete();
        userDao.insert();
        userDao.select();
        userDao.update();
    }
    @Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setPrefix("/WEB-INF/pages/");//模板文件位置
        viewResolver.setSuffix(".jsp");// 自动解析后缀名
        return viewResolver;
    }
}

